package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         155,
		Discription: "最小栈",
		Level:       2,
		Labels: map[string]int{
			"栈": 1,
			"单调栈": 1,
		},
	})
}

type MinStack struct {
	s    []int
	minS []int
}

func Constructor2() MinStack {
	return MinStack{
		s:    make([]int, 0),
		minS: make([]int, 0),
	}
}

func (stack *MinStack) Push(val int) {
	stack.s = append(stack.s, val)
	//注意是>=0
	if len(stack.minS) == 0 || stack.minS[len(stack.minS)-1] >= val {
		stack.minS = append(stack.minS, val)
	}
}

func (stack *MinStack) Pop() {
	val := stack.s[len(stack.s)-1]
	stack.s = stack.s[:len(stack.s)-1]
	if val == stack.minS[len(stack.minS)-1] {
		stack.minS = stack.minS[:len(stack.minS)-1]
	}
}

func (stack *MinStack) Top() int {
	return stack.s[len(stack.s)-1]
}

func (stack *MinStack) GetMin() int {
	return stack.minS[len(stack.minS)-1]
}